package io.kiki.sba.registry.common.model.store;

import io.kiki.sba.registry.cache.Sizer;
import io.kiki.sba.registry.util.CollectionUtils;
import lombok.Getter;

import java.io.Serializable;
import java.util.List;

public class SubPublisherList implements Serializable, Sizer {
    public static final String className = SubPublisherList.class.getName();
    private static final long serialVersionUID = 1L;
    @Getter
    private final List<SubPublisher> subPublisherList;
    private final int byteSize;

    public SubPublisherList(List<SubPublisher> subPublisherList) {
        this.subPublisherList = subPublisherList;
        this.byteSize = calcSize();
    }

    private int calcSize() {
        int bytes = 20;
        bytes += CollectionUtils.fuzzyTotalSize(subPublisherList, SubPublisher::size);
        return bytes;
    }

    @Override
    public int size() {
        return byteSize;
    }
}
